<template>
  <div class="video-card" @click="$emit('play', video)">
    <div class="video-cover">
      <img :src="video.cover" :alt="video.title" />
      <div class="video-duration">{{ video.duration }}</div>
      <div class="video-overlay">
        <el-icon class="play-icon"><VideoPlay /></el-icon>
      </div>
    </div>
    
    <div class="video-info">
      <h3 class="video-title">{{ video.title }}</h3>
      <div class="video-meta">
        <span v-if="video.views">{{ video.views }}次观看</span>
        <span v-if="video.rating">评分: {{ video.rating }}</span>
        <span v-if="video.episodes">更新至{{ video.current || 0 }}集</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { VideoPlay } from '@element-plus/icons-vue'

defineProps<{
  video: {
    id: number
    title: string
    cover: string
    duration?: string
    views?: string
    rating?: string
    episodes?: number
    current?: number
  }
}>()

defineEmits<{
  play: [video: any]
}>()
</script>

<style lang="scss" scoped>
.video-card {
  background: var(--tx-bg-secondary);
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s ease;
  cursor: pointer;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 96, 34, 0.2);

    .video-overlay {
      opacity: 1;
    }
  }
}

.video-cover {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; // 16:9 比例
  overflow: hidden;

  img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .video-duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
  }

  .video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;

    .play-icon {
      font-size: 48px;
      color: #fff;
    }
  }
}

.video-info {
  padding: 12px;

  .video-title {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .video-meta {
    font-size: 12px;
    color: var(--tx-text-secondary);
    display: flex;
    gap: 8px;
  }
}
</style>
